//
//  ViewController.m
//  YHOCR
//
//  Created by 杨杨子 on 2018/7/23.
//  Copyright © 2018年 杨杨子. All rights reserved.
//

#import "ViewController.h"
#import "BitmapCompareUtil.h"
#import "IdCardInfoRectUtil.h"
#import "BitmapUtil.h"
#import "IdCardUtil.h"
#import "PublicTool.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *imageName = @"kkl";//@"akk"//@"ooo"
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIImage* oimage = [UIImage imageNamed:imageName];
#pragma -mark- BitmapCompareUtil
   BitmapCompareUtil *compareUtil = [[BitmapCompareUtil alloc] init];
    //1 缩放32*32
    UIImage *image = [compareUtil scaleBitmap:oimage];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 150, image.size.width, image.size.height)];
    [self.view addSubview:imageView];
    imageView.image = image;
    //2 转换灰度
    UIImage *imageTwo = [compareUtil convertGreyImg:image];
    UIImageView *imageViewTwo = [[UIImageView alloc] initWithFrame:CGRectMake(50, CGRectGetMaxY(imageView.frame)+10, imageTwo.size.width, imageTwo.size.height)];
    [self.view addSubview:imageViewTwo];
    imageViewTwo.image = imageTwo;
    //3计算哈希值
   NSString *hashS = [compareUtil getBitmapFingerprint:imageTwo];

////图片二
    UIImage *ssd = [UIImage imageNamed:@"ooo"];
    //缩放
    UIImage *timage = [compareUtil scaleBitmap:ssd];
    //灰度
    UIImage *timageTwo = [compareUtil convertGreyImg:timage];
    //计算哈希值
    NSString *thashS = [compareUtil getBitmapFingerprint:timageTwo];
    
    //4 指纹对比,49位
    NSInteger comNum = [compareUtil diffS1:hashS s2:thashS];
    
#pragma -mark- IdCardInfoRectUtil
    UIImage *or = [UIImage imageNamed:imageName];
    UIImageView *imageViewU = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageViewTwo.frame), or.size.width, or.size.height)];
    imageViewU.image = or;
    [self.view addSubview:imageViewU];
    //
   IdCardInfoRectUtil *util = [[IdCardInfoRectUtil alloc] init];
   NSArray *ss = [util getFrontScaleRectList:CGRectMake(0, 0, or.size.width, or.size.height)];
    CGRect numFrame;
    UIView *numView;
    for (NSInteger index = 0; index < ss.count; index ++) {
        NameRect *ff = [NameRect new];
        ff = ss[index];
        NSLog(@"%f==%f==%f==%f==%@",ff.left,ff.top,ff.right,ff.bottom,ff.name);

            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(ff.left, CGRectGetMaxY(imageViewTwo.frame)+ff.top, (ff.right-ff.left), (ff.bottom-ff.top))];
            [self.view addSubview:view];
            view.backgroundColor = [UIColor purpleColor];
        if ([ff.name isEqualToString:@"num"]) {
            numFrame = CGRectMake(ff.left, ff.top, ff.right-ff.left, ff.bottom-ff.top);
            numView = view;
        }
    }
    
    ////
    UIImage *imageImage = [PublicTool getPartOfImage:or rect:numFrame];
    UIImage *imageImageimageImage = [compareUtil convertGreyImg:imageImage];
    UIImageView *numImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, imageImageimageImage.size.width, imageImageimageImage.size.height)];
    [self.view addSubview:numImageView];
    numImageView.image = imageImageimageImage;
    
#pragma -mark- BitmapUtil
    BitmapUtil *ddf = [[BitmapUtil alloc] init];
  float dd = [ddf getBlackPercentFromBinary:or];
    
    
#pragma -mark- IdCardUtil
  UIImage *erzhiImage =  [ddf gray2Binary:imageImageimageImage];
    
    IdCardUtil *uutil = [IdCardUtil new];
   BOOL isId = [uutil checkFrontFeature:erzhiImage];
    
    
}

@end
